package n2503;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	static class Trie{
		String word;
		Trie next[]=new Trie[26];
	}
	
	
	static void insert(String key,String value,Trie p)
	{
		for(int i=0;i<key.length();i++)
		{
			if(p.next[key.charAt(i)-'a']==null)
			{
				p.next[key.charAt(i)-'a']=new Trie();
			}
			p=p.next[key.charAt(i)-'a'];
		}
		p.word=value;
	}
	
	static String find(String key,Trie p)
	{
		for(int i=0;i<key.length();i++)
		{
			if(p.next[key.charAt(i)-'a']==null)
			{
				return null;
			}
			p=p.next[key.charAt(i)-'a'];
		}
		return p.word;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		//Scanner cin=new Scanner(bf);
		String line=null;
		//global=0;
		//trieArr[0]=new Trie();
		//HashMap<String, String>map=new HashMap<String, String>();
		Trie root=new Trie();
		while((line=bf.readLine())!=null)
		{
			if(line.trim().equals(""))break;
			StringTokenizer st=new StringTokenizer(line);
			String value=st.nextToken();
			String key=st.nextToken();
			insert(key,value,root);
			//map.put(key, value);
		}
		while((line=bf.readLine())!=null)
		{
			//String value=map.get(line);
			String value=find(line,root);
			System.out.println(value==null?"eh":value);
		}
	}

}
